package com.example.demo.mapper;

import com.example.demo.entity.Question;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author ak
 * @since 2020-04-02
 */
@Mapper
@Repository
public interface QuestionMapper extends BaseMapper<Question> {
    /**
     * 更新问题评论数量
     * @param questionId 问题id
     */
    @Update("update question set q_comment_count = q_comment_count + 1 where q_id = #{questionId}")
    void updateCommentCount(Integer questionId);

    /**
     * 更新问题浏览量
     * @param questionId 问题id
     */
    @Update("update question set q_view_count = q_view_count + 1 where q_id = #{questionId} ")
    void updateQuestionViewCount(Integer questionId);

    /**
     * 根据id获取问题，并且更新浏览量
     * @param questionId 问题id
     * @return
     */
    Question getQuestionAndIncViewCount(Integer questionId);

}
